package com.danbay.cloud.base.constants;


import org.springframework.util.StringUtils;

/**
 *
 * @author SJG
 * 2017/9/30
 * 设备类型枚举
 */
public enum DeviceType {
    LOCK_OUT(0,"室外锁"),
    LOCK_IN(1,"室内锁"),
    SMOKE_ALARM(2,"烟雾报警器"),
    EM_METER(3,"电表"),
    WATER_METER(4,"水表"),
    CENTRAL_CONTROL(5,"中控"),
    ENTRANCE(6,"门禁"),
    PA(7,"PA"),
    COLLECTOR(8,"采集器"),
    NONE(-1,"未知");

    private final int value;
    private final String phrase;

    DeviceType(int value , String phrase){
        this.value = value;
        this.phrase = phrase;
    }

    public int value(){
        return value;
    }

    public static String getPhrase(int value){
        for(DeviceType deviceType : values()){
            if(deviceType.value == value){
                return deviceType.phrase;
            }
        }
        return "错误状态";
    }

    /**
     * 使用设备名称获取对应设备类型
     * @param deviceName
     * @return
     */
    public static DeviceType parse(String deviceName){
        if(StringUtils.isEmpty(deviceName)){
            return DeviceType.NONE;
        }
        if(deviceName.startsWith("DB-GW")){
            return DeviceType.CENTRAL_CONTROL;
        }else if(deviceName.startsWith("DB-EM")){
            return DeviceType.EM_METER;
        }else if(deviceName.startsWith("DB-WM")){
            return DeviceType.WATER_METER;
        }else if(deviceName.startsWith("DB-LK")){
            return DeviceType.LOCK_IN;
        }else if(deviceName.startsWith("DB-AC")){
            return DeviceType.ENTRANCE;
        }else if (deviceName.startsWith("DB-PA")){
            return DeviceType.PA;
        }else if (deviceName.startsWith("DB-CT")){
            return DeviceType.COLLECTOR;
        }
        return DeviceType.NONE;
    }
}